<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>魏远商城</title>
		<link rel="stylesheet" type="text/css" href="../../css/cart/pay.css" />
		<link rel="stylesheet" type="text/css" href="../../css/common/public.css" />
	</head>

	<body>
		<div id="pay-web">
		<!--顶部代码-->
		<div class="top_all">
		<div class="top">
			<div class="top_con">
				<div class="tlogin"></div>
				<div class="gotoregister" style="display: none;">免费注册</div>
				<div class="homepage">商城首页</div>
				<div class="tmyorder">我的订单<img src="../../image/turn_down.png"></div>						
				<div class="home_car"><img src="../../image/shop_car.png">购物车<span class="car_time">0</span></div>
				<div class="line_ke">联系客服<img src="../../image/turn_down.png"></div>							
			</div>		
		</div>
		<div class="loged" style="display: none;">
			<div><span class="guanli">账号管理</span>|<span class="out">退出</span></div>
			<div class="thead">
				<div class="thead_pic"><span></span></div>
				<div class="tmenber">企业会员</div>
			</div>
		</div>
		<div class="myorder">
			<span class="order_1">待支付</span>
			<span class="order_2">待发货</span>
			<span class="order_3">待收货</span>
			<span class="order_4">待评价</span>
		</div>
		<div class="tcont">
			<span class="mine1">用户帮助</span>
			<span class="mine2">联系客服</span>
			<span class="mine3">投诉建议</span>
			<span class="mine4">退换货</span>
			<span class="mine5">收货地址管理</span>
		</div>
		
		<div class="logeandsear">
			<div class="imageLogo"><img src="../../image/Logo.png"></div>
			<div class="search">
				<div>
					<img class="search-icon" src="../../image/search-icon.png"><input type="text" class="home_searchto" placeholder="魏远产品搜索" /><span class="gotosearch">搜索</span><span class="searchtips">X请输入您要搜索的内容</span>
				</div>
			</div>
	    </div>
	</div>	
	<div class="right">
			<div class="right_car"><span><img src="../../image/righr_car.png"></br>购</br>物</br>车</span></div>
		<div class="youhuiquan"><span>优</br>惠</br>券</span></div>
		<div class="qianbao"><span>钱</br>包</span></div>
		<div class="qiyeshangc"><span>企</br>业</br>商</br>城</span></div>
		<div class="totop"><span><br/>^<br/>TOP</span></div>
	</div>
		<!--<div class="top_all">
			<div class="top">
				<div class="top_con">
					<div class="tlogin">登录</div>
					<div>免费注册</div>
					<div class="tmyorder">我的订单<img src="../../image/turn_down.png"></div>
					<div><img src="../../image/shop_car.png">购物车<span class="car_time">0</span><img src="../../image/turn_down.png"></div>
					<div class="line_ke">联系客服<img src="../../image/turn_down.png"></div>
				</div>
			</div>
			<div class="loged" style="display: none;">
				<div><span class="guanli">账号管理</span>|<span class="out">退出</span></div>
				<div class="thead">
					<div class="thead_pic"><span></span></div>
					<div class="tmenber">企业会员</div>
				</div>
			</div>
			<div class="myorder">
				<span>待支付</span>
				<span>待发货</span>
				<span>待收货</span>
				<span>待评价</span>
			</div>
			<div class="tcont">
				<span>用户帮助</span>
				<span>联系客服</span>
				<span>投诉建议</span>
				<span>退换货</span>
				<span>收货地址管理</span>
			</div>

			<div class="logeandsear">
				<div><img src="../../image/Logo.png"></div>
				<div class="search">
					<div>
						<img class="search-icon" src="../../image/search-icon.png"><input type="text" placeholder="魏远产品搜索" /><span class="gotosearch">搜索</span>
					</div>
				</div>
			</div>
		</div>

		<!--右侧代码-->
		<!--<div class="right">
			<div class="right_car"><img src="../../image/righr_car.png"></br>购</br>物</br>车</div>
			<div>优</br>惠</br>券</div>
			<div>钱</br>包</div>
			<div>企</br>业</br>商</br>城</div>
			<div class="totop">——<br/>^<br/>TOP</div>
		</div>-->

		<!--<div class="wrap">

		</div>-->
		<!--头部-->
		<!--<iframe src="../common/top.html" width="100%" height="200px" frameborder="0" scrolling="no"></iframe>-->
		<!--右边-->
		<!--<iframe class="irasd" frameboder="0" scrolling="no" border="none" width="30px" height="100%" src="../common/right.html"></iframe>-->
		<!--中间-->
		
		<div>
			
			<div class="main-pay">
				<div class="pricechongdiv" style="display: none;">
			         <input type="number" placeholder="请输入充值的金额" class="pricechong"/>
		        </div>
				<div class="pay-t">选择支付方式</div>
				<div class="pay-main">
					<div>
						<div class="pay-alipay">
							<span class="selectPay"><img src="../../image/selsect2.png"/></span>
							<span><img src="../../image/pay-alipay.png"/></span>
							<span id="alipay">支付宝</span>
						</div>

						<div class="pay-balance pay-alipay">
							<span class="selectPay"><img src="../../image/selsect2.png"/></span>
							<span><img src="../../image/pay-balance.png"/></span>
							<span id="balance">余额</span>
						</div>
						<div class="pay-pay">
							支付
						</div>
					</div>
					<div class="pay-or">或</div>
					<div>
						<div class="pay-alipay">
							<span class="selectPay"><img src="../../image/selsect2.png"/></span>
							<span><img src="../../image/pay-wechat.png"/></span>
							<span id="wechat">微信支付</span>
						</div>
						<div id="pay-code" class="pay-code">
							<!--<span style="background-image: url(http://www.weiyuantech.com/upload/pay/weixin/QrCodeImages/0661616158.jpg);"></span>-->
						</div>
						<div class="pay-code1">
							打开微信扫一扫，立即支付
						</div>
					</div>
				</div>
			</div>
		</div>
		<!--弹框-->
		<div class="pop1"></div>
		<div class="pop">
			<div class="pop-t">提示 <img class="pop-img" src="../../image/creat_cancel.png"/></div>
			<div>
				<div class="pop-text">抱歉！您还未登录！</div>
				<div class="pop-y">确认</div>
			</div>
		</div>
		<!--尾部-->
		<!--底部代码-->
		<div>
			<div class="wrap_bottom"><img src="../../image/bottom.png"></div>
		</div>
		<!--<iframe class="h_bottom" marginwidth="0" marginheight="0" frameboder="0" scrolling="no" width="100%" height="auto" frameborder="0" src="../common/bottom.html"></iframe>-->
		</div>
	</body>
	<script src="../../assets/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/url.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$(function(){
//			window.onbeforeunload = function() { 
//				var unloads = document.getElementById("pay-web").value; 
//				if(unloads == null || unloads == ""){ 
//				ifRecharge='';
//				ifRecharge=null;
//				} 
//			}
			/*liyong代码开始*/
//			alert(ifRecharge);
//			alert(ifRecharge);
            var ifRecharge = localStorage.wyshopifRecharge;
            localStorage.wyshopifRecharge = '';
			if(ifRecharge&&ifRecharge==1){				
				$('.pricechongdiv').css('display','block');
				$('.pay-balance').css('display','none');
			}
			/*liyong代码结束*/
			
			
			//			支付
			/*弹框*/
			var left = ((document.body.clientWidth) - 435)/2;
			function pop(){
				$('.pop').css('left',left)
				$('.pop1').css('display','block');
				$('.pop').css('display','block');
			};
			function pop1(){
				$('.pop1').css('display','none');
				$('.pop').css('display','none');
			};
			$('.pop-img').click(function(){
				pop1();
			});
			$('.pop-y').click(function(){
				pop1();
			});
//			充值判断
			$('.pricechong').keydown(function(){
				$('#pay-code span').attr('style');
				$('.pay-main').find('.selectPay img').attr('src', '../../image/selsect2.png');
				$('.pay-main').find('.pay-code').css('display', 'none');
				$('.pay-main').find('.pay-code1').css('display', 'none');
				$('.pay-main').find('.selectPay img').attr('src', '../../image/selsect2.png');
				$('.pay-main').find('.pay-pay').css({ 'color': '#fff', 'background-color': '#ccc' });
				$('.pay-main').find('.selectPay').removeClass('act');
				$('.pay-main').find('.pay-pay').removeClass('pay');
			})
			/*弹框结束*/
			$('.pay-pay').click(function() {
				if(ifRecharge&&ifRecharge==1){
					if($(this).hasClass('pay') == true) {
						if ($('.pricechong').val()==''){
							$('.pay-alipay span').removeClass('act')
							$('.pop-text').text('请输入充值金额');
							pop();
						}else if($('.pricechong').val()!=''){
							creatOrder();
							var pay = $('.pay-main').find('.act').next().next().attr('id');
								if(pay == 'alipay') {
									alipay();
								}
						}else{
							$('.pop-text').text('系统繁忙，请稍后再试');
							pop();
						}
					} else {
						$('.pop-text').text('请选择充值方式');
						pop();
					}
					
				}else{
					if($(this).hasClass('pay') == true) {
						//判断
						var pay = $('.pay-main').find('.act').next().next().attr('id');
						console.log('》《》《》' + pay);
						if(pay == 'alipay') {
							alipay();
						}
						if(pay == 'balance') {
							balance();
						}
					} else {
						$('.pop-text').text('请选址支付方式');
						pop();
					}
				}
			})
			//			支付样式
			$('.pay-main').find('.selectPay').click(function() {
				
				//微信
				$(this).parent().parent().find('.selectPay img').attr('src', '../../image/selsect1.png');
				$(this).parent().parent().find('.selectPay').addClass('act'); //添加类
				$(this).parent().parent().siblings().find('.selectPay img').attr('src', '../../image/selsect2.png');
				$(this).parent().parent().siblings().find('.selectPay').removeClass('act'); //类
				//				支付
				$(this).parent().parent().siblings().find('.pay-pay').removeClass('pay');
				$(this).parent().parent().siblings().find('.pay-pay').css({ "color": "#ffffff", 'background-color': '#CCCCCC' });
				//				二维码
				$(this).parent().parent().find('.pay-code').css('display', 'block');
				$(this).parent().parent().find('.pay-code1').css('display', 'block');
				//余额支付宝
				$(this).parent().find('.selectPay img').attr('src', '../../image/selsect1.png');
				$(this).parent().find('.selectPay').addClass('act'); //添加类
				$(this).parent().siblings().find('.selectPay img').attr('src', '../../image/selsect2.png');
				$(this).parent().siblings().find('.selectPay').removeClass('act'); //类
				//				支付
				$(this).parent().parent().find('.pay-pay').addClass('pay');
				$(this).parent().parent().find('.pay-pay').css({ 'color': '#000', 'background-color': '#FFC100' });
				//				二维码隐藏
				$(this).parent().parent().siblings().find('.pay-code').css('display', 'none');
				$(this).parent().parent().siblings().find('.pay-code1').css('display', 'none');
				//微信支付
				var pay = $('.pay-main').find('.act').next().next().attr('id');
				if(ifRecharge&&ifRecharge==1){
						    
						if ($('.pricechong').val()==''){
							$('.pay-alipay span').removeClass('act')
							$(this).parent().parent().find('.selectPay img').attr('src', '../../image/selsect2.png');
							$(this).parent().parent().find('.pay-pay').css({ 'color': '#fff', 'background-color': '#ccc' });
							$('.pop-text').text('请输入充值金额');
							pop();
						}else if($('.pricechong').val()!=''){
							
							$(this).parent().parent().find('.selectPay img').attr('src', '../../image/selsect1.png');
							$(this).parent().parent().find('.pay-pay').css({ 'color': '#000', 'background-color': '#FFC100' });
							var pay = $('.pay-main').find('.act').next().next().attr('id');
							if(pay == 'wechat') {
//								wechat();
                                creatOrder();
							}
						}else{
							$('.pop-text').text('系统繁忙，请稍后再试');
							pop();
						}
				}else{
					if(pay == 'wechat') {
						wechat();
					}
				}
			})
			
			
			/*liyong代码开始*/
			 /*充值创建订单*/
			function creatOrder() {
				$.ajax({
						url: ur + '/mobilemember/frontOrder/createOrder',
						type: 'POST',
						headers: {
							"X-Token": localStorage.wyshoptoken
						},
						dataType: 'json',
						data: {
							"orderVO.orderPay": $('.pricechong').val(),
							"type": 1,
						},
				})
					.done(function(data) {
						console.log(JSON.stringify(data));
						if(data.result.meta.code == 200){
							localStorage.sureorderid = data.result.data.orderId;
							wechat();
							setInterval(actionjiekou,1000);
						}
					})
			}
			/*liyong代码结束*/
			
			function actionjiekou(){
				
				$.ajax({
					url: ur + '/mobilemember/frontOrderOperation/orderRun',
					headers: {
						"X-Token": localStorage.wyshoptoken
					},
					type: 'POST',
					dataType: 'json',
					data: {
						'orderVO.id': localStorage.sureorderid, //订单编号						
					},
					success: function(data) {
						console.log(JSON.stringify(data));
						if(data.result.meta.code == 200){
                             window.location.replace("paysuccess.html");
						}
					}
				})
			}
			
			
			
			//接口对接
			//微信支付
			function wechat(){
				$.ajax({
					url: ur + '/payment/wxpay/unifiedorder',
					headers: {
						"X-Token": localStorage.wyshoptoken
					},
					type: 'POST',
					dataType: 'json',
					data: {
						'orderVO.id': localStorage.sureorderid, //订单编号
						'payType': 'scan'
					},
					success: function(data) {
						console.log(JSON.stringify(data));
						if(data.meta.code == 200){
							
//							ifRecharge=null;
							var imgCode = data.data.msg;
							var payCode = imgCode.replace('\\', '/');
							document.getElementById('pay-code').innerHTML = '<span style="background-image: url(' + picur + payCode + ');"></span>';
						} else {
							$('.pop-text').text('暂不支持此支付方式，请选择其他方式支付');
							pop();
						}
					}
				})
			}
			
			
			
			
			
			
			/*余额支付*/
			function balance() {
				$.ajax({
					url: ur + '/payment/alipay/useBalancePay',
					type: 'POST',
					headers: {
						"X-Token": localStorage.wyshoptoken
					},
					dataType: 'json',
					data: {
						"orderVO.orderNum": localStorage.sureorder, //	订单号
					},
					success: function(data) {
						console.log(JSON.stringify(data))
						if(data.result.code == 200) {
//							localStorage.wypaySuccess = wypaySuccess;
							window.location.replace("paysuccess.html");
//							$('.pop-y').click(function(){
//								alert(1)
//								window.location.replace("paysuccess.html");
//								
//								pop1();
//								
//							});
						} else if(data.result.code == 201) {
							$('.pop-text').text('账户不存在');
							pop();
						} else if(data.result.code == 202) {
							$('.pop-text').text('余额不足，前往充值...');
							pop();
						} else if(data.result.code == 203) {
							$('.pop-text').text('订单不存在');
							pop();
						} else if(data.result.code == 110) {
							$('.pop-text').text('系统繁忙，请稍后重试');
							pop();
						}
					},
					error: function(error) {
						console.log('系统错误')
					}
				})
			}
			
			/*支付宝支付*/
			function alipay() {
				$.ajax({
					url: ur + "/payment/alipay/banksPay",
					type: "post",
					headers: {
						'X-Token': localStorage.wyshoptoken
					},
					dataType: "json",
					data: {
						"orderVO.id": localStorage.sureorderid,
						"payType": 'PC',
					},
					success: function(data) {
						if(data.meta.code == "200") {
							
							$("body").html(data.data);
						} else {
							$('.pop-text').text('系统繁忙，请稍后重试');
							pop();
						}

					}
				});
			}
		})
	</script>

</html>